/**
 * Created by Butterfly on 27.11.2012
 */
package com.lohika;

import java.util.Arrays;

/**
 * @author Butterfly
 *
 * I created this wrapper because the problem is that 
 * byte[] uses object identity for equals and hashCode, 
 * so that for example
 * byte[] b1 = {1, 2, 3}
 * byte[] b2 = {1, 2, 3} 
 * will not match in a HashMap
 */ 
public class ByteArrayWrapper {
	
	private final byte[] data;

	public ByteArrayWrapper(byte[] data) {
		if (data == null) {
			throw new NullPointerException();
		}
		this.data = data;
	}
	
	public byte[] getData() {
		return data;
	}

	@Override
	public boolean equals(Object other) {
		if (!(other instanceof ByteArrayWrapper)) {
			return false;
		}
		return Arrays.equals(data, ((ByteArrayWrapper) other).data);
	}

	@Override
	public int hashCode() {
		return Arrays.hashCode(data);
	}

	@Override
	public String toString() {
		return "ByteArrayWrapper [data=" + Arrays.toString(data) + "]";
	}

}
